package com.atguigu.springcloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.atguigu.springcloud.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

@EnableBinding(Source.class) //进行绑定,就是stream的bindder,这里绑定Source,表示这是输出
public class MessageServiceImpl implements IMessageService {
	
	@Autowired
	private MessageChannel output; //注入message的通道
	
	@Override
	public String send() {
		String uuid = IdUtil.randomUUID();//生成一个uuid
		//使用通道进行发送消息,send()方法中是一个Message参数,参照官网使用MessageBuilder进行构建
		output.send(MessageBuilder.withPayload(uuid).build());
		return uuid;
	}
}
